import axios from 'axios'
import { store } from '../redux/store'

// 创建axios实例
axios.defaults.baseURL="http://localhost:5000"

// request拦截器
axios.interceptors.request.use(config => {
    //显示loading
    store.dispatch({
        type: 'changeLoading',
        data:true
    })
    return config
}, error => {
    Promise.reject(error)
})

// respone拦截器
axios.interceptors.response.use(
    //隐藏loading
    response => {
        store.dispatch({
            type: 'changeLoading',
            data: false
        });
        return response
    },
    error => {
        store.dispatch({
            type: 'changeLoading',
            data: false
        });
        return Promise.reject(error)
    }
)


// 重新封装，按找目前vue项目的来做